package com.leyou.item.api;


import com.Jshop.common.pojo.PageResult;
import com.leyou.item.bo.SpuBo;
import com.leyou.item.pojo.Sku;
import com.leyou.item.pojo.Spu;
import com.leyou.item.pojo.SpuDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 返回值不再使用ResponseEntity
 * 如果使用ResponseEntity还需要对http数据包进行解包操作
 *
 * 提供与Controller完全一致的定义(返回值可以直接解包)让调用方填写参数
 * 调用方通过Feign远程调用的是Controller
 *
 * */


public interface GoodsApi {


    //分页查询商品
    @GetMapping("spu/page")
    PageResult<SpuBo> querySpuByPage(
            @RequestParam(value = "key",required = false) String key,
            @RequestParam(value = "saleable", required = false) Boolean saleable,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows);


    //根据spu商品id查询详情
    @GetMapping("/spu/detail/{id}")
    SpuDetail querySpuDetailById(@PathVariable("id") Long id);


    @GetMapping("spu/{id}")
    Spu querySpuById(@PathVariable("id") Long id);

    //根据spu的id查询sku
    @GetMapping("sku/list")
    List<Sku> querySkuBySpuId(@RequestParam("id") Long id);

    @GetMapping("sku/{id}")
    Sku querySkuById(@PathVariable("id") Long id);

    @GetMapping("skus")
    List<Sku> querySkusByList(@PathVariable("id") Long id);

    //改成以JSON形式传递
    @RequestMapping(value = "decr", method = RequestMethod.POST)
    void decrementStock(@RequestBody Map<String, Integer> decrMap);

}